****************************************************************
****                                                        ****
****                 Hyeok Yong Kwon                        ****
****                 Korea University                       ****
****                 hkwon@korea.ac.kr                      ****
****            PRQ Replication Code For:                   ****
**** "Government Partisanship and Electoral Accountability" ****
****                                                        ****
****************************************************************

** analyzed BEPS 92-97, 97-01 separately

** set working directory

** 1992-97 

set more off

use beps9297_replication.dta, clear

sort serialno streg92

svyset [pweight=wtfactor], strata(streg92) 

/************/
/* Figure 1 */
/************/

* See R code

/****************************/
/* Results for Figure 2 (a) */
/****************************/

* See R code for graphics 

gen con92=1 if cvo92==1
replace con92=0 if con92~=1
gen lab92=1 if lvo92==1
replace lab92=0 if lab92~=1
gen ld92=1 if vot92==3
replace ld92=0 if ld92~=1
gen absten92=1 if voted92==2 
replace absten92=0 if absten92~=1

gen con97=1 if cvo97==1
replace con97=0 if con97~=1
gen lab97=1 if lvo97==1
replace lab97=0 if lab97~=1
gen ld97=1 if vot97==3
replace ld97=0 if ld97~=1
gen absten97=1 if voted97==2
replace absten97=0 if absten97~=1

gen conloyal=1 if cvo92==1 & cvo97==1
replace conloyal=0 if conloyal~=1
gen labloyal=1 if lvo92==1 & lvo97==1
replace labloyal=0 if labloyal~=1
gen ldloyal=1 if ld92==1 & ld97==1
replace ldloyal=0 if ldloyal~=1
gen absten=1 if absten92==1 & absten97==1
replace absten=0 if absten~=1

gen contolab=1 if cvo92==1 & lvo97==1
replace contolab=0 if contolab~=1
gen contold=1 if cvo92==1 & ld97==1
replace contold=0 if contold~=1
gen contoabs=1 if cvo92==1 & absten97==1
replace contoabs=0 if contoabs~=1

gen labtocon=1 if lvo92==1 & cvo97==1
replace labtocon=0 if labtocon~=1
gen labtold=1 if lvo92==1 & ld97==1
replace labtold=0 if labtold~=1
gen labtoabs=1 if lvo92==1 & absten97==1
replace labtoabs=0 if labtoabs~=1

gen ldtocon=1 if ld92==1 & cvo97==1
replace ldtocon=0 if ldtocon~=1
gen ldtolab=1 if ld92==1 & lvo97==1
replace ldtolab=0 if ldtolab~=1
gen ldtoabs=1 if ld92==1 & absten97==1
replace ldtoabs=0 if ldtoabs~=1

gen abstocon=1 if absten92==1 & cvo97==1
replace abstocon=0 if abstocon~=1
gen abstolab=1 if absten92==1 & lvo97==1
replace abstolab=0 if abstolab~=1
gen abstold=1 if absten92==1 & ld97==1
replace abstold=0 if abstold~=1

tabstat conloyal labloyal ldloyal absten contolab contold contoabs labtocon labtold labtoabs ldtocon ldtolab ldtoabs abstocon abstolab abstold 

/*************/
/* Figure 3  */
/*************/

* See R code; use dist.csv data

/*******************/
/* Table 1 1992-97 */
/*******************/

/* Cons, Lab, Lib Dem, Abstention */

gen transs=1 if vot97==1 		/* Conservative vote */
replace transs=2 if vot97==2 	/* Labour vote */
replace transs=3 if vot97==3 	/* Lib Dem vote */
replace transs=4 if voted97==2 	/* didn't vote */

gen lvo92unem97=lvo92*unem97

mlogit transs unem97 lvo92 lvo92unem97 nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 [pw=wtfactor], base(1) robust cluster(streg97)

predict pppp1, outcome(1) /* conservative */
predict pppp2, outcome(2) /* labour */
predict pppp3, outcome(3) /* lib dem */
predict pppp4, outcome(4) /* abstention */

/************************/
/* Results for Figure 4 */
/************************/

* Predicted probabilities and simulations 

gen byte ee97 = unem97        /* save real unemployment assessment */

replace unem97 = 1           /* make everyone 'good' */

predict ggcon97, outcome(1)  /* predicted probabilities */
predict gglab97, outcome(2) 
predict ggld97, outcome(3) 
predict ggabs97, outcome(4)

replace unem97 = 5           /* make everyone worried */

predict wwcon97, outcome(1) 
predict wwlab97, outcome(2)
predict wwld97, outcome(3)
predict wwabs97, outcome(4)

replace unem97 = ee97        /* restore real measure */

summarize ggcon97 gglab97 ggld97 ggabs97 wwcon97 wwlab97 wwld97 wwabs97


/*******************************/
/* Table 2 and Table 3 1992-97 */
/*******************************/

/* Previous Non-Labour Voters */

logistic lvo97 unem97 nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==0, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab unem97
prvalue, x(unem97=1)
prvalue, x(unem97=5)

* requires Clarfiy package

estsimp logit lvo97 unem97 nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==0, genname(a)

setx median
setx unem97 1
simqi, prval(1)
simqi, fd(prval(1)) changex(unem97 1 5)

/* Previous Labour Voters */

logistic lvo97 unem97 nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==1, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab unem97
prvalue, x(unem97=1)
prvalue, x(unem97=5)

estsimp logit lvo97 unem97 nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==1, genname(b)

setx median
setx unem97 1
simqi, prval(1)
simqi, fd(prval(1)) changex(unem97 1 5)

/*******************************************/
/* Results for Figure 5 1992-97 (Table A1) */
/*******************************************/

* See R code for graphics 

gen lswingg=1 if lvo97==1 & lvo92==0
replace lswingg=0 if lvo97==1 & lvo92==1
replace lswingg=. if lswingg~=1 & lswingg~=0

sort lswingg
ttest unem97, by(lswingg) unequal
ttest dunem, by(lswingg) unequal
ttest jobs97, by(lswingg) unequal
ttest tax97, by(lswingg) unequal

/*******************/
/* Table 4 1992-97 */
/*******************/

* 1) First row in Table 4 without economic evaluations 

/* Previous Non-Labour Voters */

logistic lvo97 unem97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==0, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab unem97
prvalue, x(unem97=1)
prvalue, x(unem97=5)

estsimp logit lvo97 unem97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==0, genname(c)

setx median
setx unem97 1
simqi, prval(1)
simqi, fd(prval(1)) changex(unem97 1 5)

/* Previous Labour Voters */

logistic lvo97 unem97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==1, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab unem97
prvalue, x(unem97=1)
prvalue, x(unem97=5)

estsimp logit lvo97 unem97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==1, genname(d)

setx median
setx unem97 1
simqi, prval(1)
simqi, fd(prval(1)) changex(unem97 1 5)


* 2) Second row in Table 4 without employment evaluations 

/* Previous Non-Labour Voters */

logistic lvo97 nat97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==0, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab nat97
prvalue, x(nat97=1)
prvalue, x(nat97=5)

estsimp logit lvo97 nat97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==0, genname(f)

setx median
setx nat97 1
simqi, prval(1)
simqi, fd(prval(1)) changex(nat97 1 5)

/* Previous Labour Voters */

logistic lvo97 nat97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==1, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab nat97
prvalue, x(nat97=1)
prvalue, x(nat97=5)

estsimp logit lvo97 nat97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==1, genname(g)

setx median
setx nat97 1
simqi, prval(1)
simqi, fd(prval(1)) changex(nat97 1 5)

* 3) Third row in Table 4 with changes in employment evaluations 

/* Previous Non-Labour Voters */

logistic lvo97 dunem nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==0, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab dunem
prvalue, x(dunem=-4)
prvalue, x(dunem=4)

estsimp logit lvo97 dunem nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==0, genname(h)

setx median
setx dunem 0
simqi, prval(1)
simqi, fd(prval(1)) changex(dunem -4 4)

/* Previous Labour Voters */

logistic lvo97 dunem nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==1, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab dunem
prvalue, x(dunem=-4)
prvalue, x(dunem=4)

estsimp logit lvo97 dunem nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97 if lvo92==1, genname(j)

setx median
setx dunem 0
simqi, prval(1)
simqi, fd(prval(1)) changex(dunem -4 4)

/*******************/
/* Table 5 1992-97 */
/*******************/

logistic lvo97 unem97 lvo92 lvo92unem nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97, robust cluster(streg97) 

lstat
lroc, nograph
logit
fitstat
prtab unem97
prtab lvo92unem 
prvalue, x(unem97=1)
prvalue, x(unem97=5)
prvalue, x(lvo92unem=1)
prvalue, x(lvo92unem=5)

estsimp logit lvo97 unem97 lvo92 lvo92unem nat97 hou97 lr97 eec97 lo97 mi97 age97 fem97 edu92 uni97 sou97, genname(k)

setx median
setx unem97 1 (lvo92unem lvo92) 0
simqi, prval(1)
simqi, fd(prval(1)) changex(unem97 1 5) 

setx median
setx (lvo92unem unem97 lvo92) 1
simqi, prval(1)
simqi, fd(prval(1)) changex((lvo92unem unem97) 1 5) 



**********************
** 1997-01 analysis 
**********************

use beps9701_replication.dta, clear

svyset [pweight=wtergb], strata(streg97) 

/****************************/
/* Results for Figure 2 (b) */
/****************************/

* See R code for graphics 

gen con97=1 if vote97==1
replace con97=0 if con97~=1
gen lab97=1 if vote97==2
replace lab97=0 if lab97~=1
gen ld97=1 if vote97==3
replace ld97=0 if ld97~=1
gen absten97=1 if voted97==2 
replace absten97=0 if absten97~=1

gen vo97=1 if con97==1
replace vo97=2 if lab97==1
replace vo97=3 if ld97==1
replace vo97=4 if absten97==1

gen con01=1 if vote01==1
replace con01=0 if con01~=1
gen lab01=1 if vote01==2
replace lab01=0 if lab01~=1
gen ld01=1 if vote01==3
replace ld01=0 if ld01~=1
gen absten01=1 if voted01==2
replace absten01=0 if absten01~=1

gen conloyal=1 if con97==1 & con01==1
replace conloyal=0 if conloyal~=1
gen labloyal=1 if lab97==1 & lab01==1
replace labloyal=0 if labloyal~=1
gen ldloyal=1 if ld97==1 & ld01==1
replace ldloyal=0 if ldloyal~=1
gen abstenal=1 if absten97==1 & absten01==1
replace abstenal=0 if abstenal~=1

gen contolab=1 if con97==1 & lab01==1
replace contolab=0 if contolab~=1
gen contold=1 if con97==1 & ld01==1
replace contold=0 if contold~=1
gen contoabs=1 if con97==1 & absten01==1
replace contoabs=0 if contoabs~=1

gen labtocon=1 if lab97==1 & con01==1
replace labtocon=0 if labtocon~=1
gen labtold=1 if lab97==1 & ld01==1
replace labtold=0 if labtold~=1
gen labtoabs=1 if lab97==1 & absten01==1
replace labtoabs=0 if labtoabs~=1

gen ldtocon=1 if ld97==1 & con01==1
replace ldtocon=0 if ldtocon~=1
gen ldtolab=1 if ld97==1 & lab01==1
replace ldtolab=0 if ldtolab~=1
gen ldtoabs=1 if ld97==1 & absten01==1
replace ldtoabs=0 if ldtoabs~=1

gen abstocon=1 if absten97==1 & con01==1
replace abstocon=0 if abstocon~=1
gen abstolab=1 if absten97==1 & lab01==1
replace abstolab=0 if abstolab~=1
gen abstold=1 if absten97==1 & ld01==1
replace abstold=0 if abstold~=1

tabstat conloyal labloyal ldloyal abstenal contolab contold contoabs labtocon labtold labtoabs ldtocon ldtolab ldtoabs abstocon abstolab abstold 

/*******************/
/* Table 1 1997-01 */
/*******************/

/* Cons, Lab, Lib Dem, Abstention */

gen transs=1 if vote01==1 		/* conservative vote */
replace transs=2 if vote01==2 	/* labour vote */
replace transs=3 if vote01==3 	/* lib dem vote */
replace transs=4 if absten==1 	/* abstention */

gen lvo97unem98=lvo97*unem98

mlogit transs unem98 lvo97 lvo97unem98 nat01 hou01 lr01 eec01 lo97 mi97 edu01 age01 fem97 uni97 sou97, base(1) robust cluster(streg97)

predict pppp1, outcome(1) /* conservative */
predict pppp2, outcome(2) /* labour */
predict pppp3, outcome(3) /* lib dem */
predict pppp4, outcome(4) /* abstention */


/********************/
/* Table 2  1997-01 */
/********************/

/* Previous non-Labour voters */

logistic lvo01 unem98 nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==0, robust cluster(streg97)

lstat
lroc, nograph
logit

prtab unem98		
prvalue, x(unem98=1)	
prvalue, x(unem98=5)	

estsimp logit lvo01 unem98 nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==0, genname(aa)

setx median
setx unem98 1
simqi, prval(1)
simqi, fd(prval(1)) changex(unem98 1 5) 

/* Previous Labour voters */

logistic lvo01 unem98 nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==1, robust cluster(streg97)

lstat
lroc, nograph
logit

prtab unem98		
prvalue, x(unem98=1)	
prvalue, x(unem98=5)	

estsimp logit lvo01 unem98 nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==1, genname(bb)

setx median
setx unem98 1
simqi, prval(1)
simqi, fd(prval(1)) changex(unem98 1 5) 

/*******************************************/
/* Results for Figure 5 1997-01 (Table A1) */
/*******************************************/

* See R code for graphics 

gen lswingg=1 if lvo01==1 & lvo97==0
replace lswingg=0 if lvo01==1 & lvo97==1
replace lswingg=. if lswingg~=1 & lswingg~=0

sort lswingg 						/* labor switchers vs. labor voters */
ttest unem98, by(lswingg) unequal
ttest emp01, by(lswingg) unequal
ttest redi01, by(lswingg) unequal
ttest welfare01, by(lswingg) unequal

/*******************/
/* Table 4 1997-01 */
/*******************/

* 1) First row in Table 4 without economic evaluations 

/* Previous non-Labour voters */

logistic lvo01 unem98 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==0, robust cluster(streg97)

lstat
lroc, nograph
logit

prtab unem98		
prvalue, x(unem98=1)	
prvalue, x(unem98=5)	

estsimp logit lvo01 unem98 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==0, genname(cc)

setx median
setx unem98 1
simqi, prval(1)
simqi, fd(prval(1)) changex(unem98 1 5) 

/* Previous Labour voters */

logistic lvo01 unem98 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==1, robust cluster(streg97)

lstat
lroc, nograph
logit

prtab unem98		
prvalue, x(unem98=1)	
prvalue, x(unem98=5)	

estsimp logit lvo01 unem98 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==1, genname(dd)

setx median
setx unem98 1
simqi, prval(1)
simqi, fd(prval(1)) changex(unem98 1 5) 

* 2) Second row in Table 4 without employment evaluations 

/* Previous non-Labour voters */

logistic lvo01 nat01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==0, robust cluster(streg97)

lstat
lroc, nograph
logit

estsimp logit lvo01 nat01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==0, genname(ee)

/* Previous Labour voters */

logistic lvo01 nat01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==1, robust cluster(streg97)

lstat
lroc, nograph
logit

estsimp logit lvo01 nat01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==1, genname(ff)

* 3) Third row in Table 4 with changes in employment evaluations 

/* Previous non-Labour voters */

logistic lvo01 dunem nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==0, robust cluster(streg97)

lstat
lroc, nograph
logit

prtab dunem		
prvalue, x(dunem=-4)	
prvalue, x(dunem=4)	

estsimp logit lvo01 dunem nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==0, genname(gg)

setx median
setx dunem 0
simqi, prval(1)
simqi, fd(prval(1)) changex(dunem -4 4) 

/* Previous Labour voters */

logistic lvo01 dunem nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==1, robust cluster(streg97)

lstat
lroc, nograph
logit

prtab dunem		
prvalue, x(dunem=-4)	
prvalue, x(dunem=4)	

estsimp logit lvo01 dunem nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97 if lvo97==1, genname(hh)

setx median
setx dunem 0
simqi, prval(1)
simqi, fd(prval(1)) changex(dunem -4 4) 

/*******************/
/* Table 5 1997-01 */
/*******************/

logistic lvo01 unem98 lvo97 lvo97unem98 nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97, robust cluster(streg97) 

lstat
lroc, nograph
logit

prtab unem98
prtab lvo97unem98 
prvalue, x(unem98=1)
prvalue, x(unem98=5)
prvalue, x(lvo97unem98=0)
prvalue, x(lvo97unem98=5)

estsimp logit lvo01 unem98 lvo97 lvo97unem98 nat01 hou01 lr01 eec01 lo97 mi97 age01 fem97 edu01 uni97 sou97, genname(kk)

setx median
setx unem98 1 (lvo97unem98 lvo97) 0
simqi, prval(1)
simqi, fd(prval(1)) changex(unem98 1 5) 

setx median
setx (lvo97unem98 unem98 lvo97) 1
simqi, prval(1)
simqi, fd(prval(1)) changex((lvo97unem98 unem98) 1 5) 





